(function($){
	var ms = {
		init:function(obj,args){
			return (function(){
				ms.fillHtml(obj,args);
				ms.bindEvent(obj,args);
			})();
		},
		//填充html
		fillHtml:function(obj,args){
			return (function(){
				obj.empty();
				//上一页
				if(args.current_a > 1){
					obj.append('<a href="javascript:;" class="prevPage_a">上一页</a>');
				}else{
					obj.remove('.prevPage_a');
					obj.append('<span class="disabled">上一页</span>');
				}
				//中间页码
				if(args.current_a != 1 && args.current_a >= 4 && args.pageCount_a != 4){
					obj.append('<a href="javascript:;" class="tcdNumber_a">'+1+'</a>');
				}
				if(args.current_a-2 > 2 && args.current_a <= args.pageCount_a && args.pageCount_a > 5){
					obj.append('<span>...</span>');
				}
				var start = args.current_a -2,end = args.current_a+2;
				if((start > 1 && args.current_a < 4)||args.current_a == 1){
					end++;
				}
				if(args.current_a > args.pageCount_a-4 && args.current_a >= args.pageCount_a){
					start--;
				}
				for (;start <= end; start++) {
					if(start <= args.pageCount_a && start >= 1){
						if(start != args.current_a){
							obj.append('<a href="javascript:;" class="tcdNumber_a">'+ start +'</a>');
						}else{
							obj.append('<span class="current_a">'+ start +'</span>');
						}
					}
				}
				if(args.current_a + 2 < args.pageCount_a - 1 && args.current_a >= 1 && args.pageCount_a > 5){
					obj.append('<span>...</span>');
				}
				if(args.current_a != args.pageCount_a && args.current_a < args.pageCount_a -2  && args.pageCount_a != 4){
					obj.append('<a href="javascript:;" class="tcdNumber_a">'+args.pageCount_a+'</a>');
				}
				//下一页
				if(args.current_a < args.pageCount_a){
					obj.append('<a href="javascript:;" class="nextPage_a">下一页</a>');
				}else{
					obj.remove('.nextPage_a');
					obj.append('<span class="disabled">下一页</span>');
				}
			})();
		},
		//绑定事件
		bindEvent:function(obj,args){
			return (function(){
				obj.on("click","a.tcdNumber_a",function(e){
					e.stopPropagation();
					var current_a = parseInt($(this).text());
					ms.fillHtml(obj,{"current_a":current_a,"pageCount_a":args.pageCount_a});
					if(typeof(args.backFn_a)=="function"){
						args.backFn_a(current_a);
					}
				});
				//上一页
				obj.on("click","a.prevPage_a",function(e){
					e.stopPropagation();
					var current_a = parseInt(obj.children("span.current_a").text());
					ms.fillHtml(obj,{"current_a":current_a-1,"pageCount_a":args.pageCount_a});
					if(typeof(args.backFn_a)=="function"){
						args.backFn_a(current_a-1);
					}
				});
				//下一页
				obj.on("click","a.nextPage_a",function(e){
					e.stopPropagation();
					var current_a = parseInt(obj.children("span.current_a").text());
					ms.fillHtml(obj,{"current_a":current_a+1,"pageCount_a":args.pageCount_a});
					if(typeof(args.backFn_a)=="function"){
						args.backFn_a(current_a+1);
					}
				});
			})();
		}
	}
	$.fn.createPage_a = function(options){
		var args = $.extend({
			pageCount_a : 10,
			current_a : 1,
			backFn_a : function(e){e.stopPropagation()}
		},options);
		ms.init(this,args);
	}
})(jQuery);
